<?php

namespace App\Repositories\Criteria;

use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;

/**
 * Class PmSelectCriteria
 * @package namespace App\Repositories\Criteria;
 */
class PmSelectCriteria implements CriteriaInterface
{
    public $pm_id;
    public $field;

    public function __construct($pm_id, $field = 'pm_id')
    {
        $this->pm_id = $pm_id;
        $this->field = $field;
    }

    /**
     * Apply criteria in query repository
     *
     * @param                     $model
     * @param RepositoryInterface $repository
     *
     * @return mixed
     */
    public function apply($model, RepositoryInterface $repository)
    {
        if ($this->pm_id != 0) {
            return $model->where($this->field, $this->pm_id);
        }
        return $model;
    }
}
